<?php
/**
* @version $Id: controller.php 18 2009-12-07 11:22:56Z truongnhan0311 $
* @author truongnhan0311
* @package    wrd component
*/
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
$lang =& JFactory::getLanguage();


$page_heading = JTEXT::_('WRD_MYACCOUNT_POINT_SUMMARY');
$title = JText::_('WMCVIP_TITLE_PREFIX').$page_heading.JText::_('WMCVIP_TITLE_SUFIX');
$document = &JFactory::getDocument();
$document->setTitle($title) ;
?>
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css" rel="stylesheet">
<link href="http://netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome-ie7.css" rel="stylesheet">
<link rel="stylesheet" href="<?php JURI::base(); ?>templates/wrd/stylesheets/foundation-datepicker.css" type="text/css" />

<div class="row">
	<div class="twelve columns all_reward_header">
		<?php echo $page_heading; ?>
	</div>
</div>

<div class="row form_view_point">
	<div class="two columns user_point">
		<div class="row">
			<div class="twelve columns total">
				<?php echo JTEXT::_('WRD_MYACCOUNT_TOTAL')?>
			</div>
		</div>
		<div class="row">
			<div class="twelve columns p_o_u">
				<?php echo number_format($this->profile->p_o_u,0,'.',','); ?>
			</div>
		</div>
	</div>
	<div class="ten columns">
		<form id="show_point_range" name="show_point_range" method="post" action="<?php echo JRoute::_('index.php?option=com_wrd&view=profile&layout=myaccount&Itemid=119'); ?>" >
			<div class="row user_detail">
				<div class="six columns">
					<?php echo JTEXT::_('WRD_MYACCOUNT_MEMBER_ID_ASSIGNED')?>
					<strong><?php echo  $this->profile->member_id; ?></strong>
				</div>
				<div class="six columns">
					<?php echo JTEXT::_('WRD_MYACCOUNT_MEMBER_NAME')?>
					<strong><?php echo  $this->profile->l_name.' '.$this->profile->f_name ?></strong>
				</div>
			</div>
			<div class="row form_select" >
				<div class="four columns">
					<?php echo JHTML::_('wrd.listViewOptionFrontEnd','special_range',$this->special_range,'onchange="this.form.submit()"'); ?>
					
				</div>
				<div class="three columns">
					<div class="row date collapse" id="dpFromYears" data-date="" data-date-format="dd-mm-yyyy" data-date-viewmode="years">
						<input class="columns ten" id="point_from_date" name="point_from_date"  size="16" type="text" value="<?php echo $this->point_from_date ?>" readonly>	
						<span class="prefix columns two end">
							<i class="icon-calendar"></i>
						</span>			
					</div>	
				</div>
				<div class="three columns">
					<div class="row date collapse" id="dpToYears" data-date="" data-date-format="dd-mm-yyyy" data-date-viewmode="years">
						<input class="columns ten" id="point_to_date" name="point_to_date"  size="16" type="text" value="<?php echo $this->point_to_date ?>" readonly>	
						<span class="prefix columns two end">
							<i class="icon-calendar"></i>
						</span>			
					</div>	
				</div>
				<div class="two columns">
					
					<input class="date_submit" type="submit" name="show" value="<?php echo JText::_(WRD_MYACCOUNT_SHOW); ?>">
				</div>
			</div>
		</form>
	</div>
</div>
<?php
    if(count($this->level1)):
?>
<table  class="tblmypoint twelve" cellpadding="0" cellspacing="0">
    <thead>
        <tr>
            <th><?php echo JTEXT::_('WRD_MYACCOUNT_STT')?></th>
            <th><?php echo JTEXT::_('WRD_MYACCOUNT_REF')?></th>
            <th><?php echo JTEXT::_('WRD_MYACCOUNT_DATE')?></th>
            <th><?php echo JTEXT::_('WRD_MYACCOUNT_NOTE')?></th>
            <th><strong><?php echo JTEXT::_('WRD_MYACCOUNT_POINT')?></strong></th>
            <th class="last_cell"><?php echo JTEXT::_('WRD_MYACCOUNT_DATE_EXPIRE')?></th>
        </tr>
    </thead>
    <tbody>
       <?php
       $className = "";
       $i=0;
        foreach ($this->level1 as $raw=>$level1_item):
 			
 			if($i%2 == 0)$className = "chan";
 			else $className = "le";
 			$i++;
 			if($level1_item->type == 2)
				$sub = 0;
			elseif($level1_item->total > 1 || $level1_item->type == 0)
       			$sub = 1;
			elseif($level1_item->total == 1 && $level1_item->type == 9)
				$sub = 1;
			else
				$sub = 0;
			
			$attr = ($sub == 1) ? "class= 'has_sub $className'" : ''; 
       	 ?>
       	<tr <?php echo $attr;  ?> >
       		<td style="text-align: center;"><?php echo $raw+1; ?></td>
       		<td style="text-align: center;">
       			<?php if($sub == 1): ?>
       			<a class="expand" id="top_<?php echo $level1_item->type ?>_<?php echo $raw; ?>"><img src="images/icon_expand.gif"></a>
       			<?php endif; ?>
       		</td>
       		<td style="text-align: center;">
       			<?php echo date('d/m/Y',strtotime($level1_item->created_date));?>
       		</td>
       		<td>
       			<?php echo $level1_item->des; ?>
       		</td>
       		<td style="text-align: right;">
       			<?php if($level1_item->type == 9):?>-<?php endif; ?>
       			<?php if($level1_item->total == 1 && $level1_item->type != 9): ?>
       				<?php echo number_format($level1_item->point,0,'.',','); ?>
        		<?php else: ?>
       				<?php echo number_format($level1_item->sub_level2->total,0,'.',','); ?>
       			<?php endif;?>
       		</td>
       		<td style="text-align: center;">
       			<?php if($level1_item->expire != '0000-00-00'): ?>
       				<?php if(strtotime($level1_item->expire) < time() && $level1_item->expire != '0000-00-00'):?>
       					<font color="#800000"><?php echo date('d/m/Y',strtotime($level1_item->expire));?></font>
       				<?php else: ?>
       					<?php echo date('d/m/Y',strtotime($level1_item->expire));?>
       				<?php endif; ?>
       			<?php endif; ?>
       		</td>
       	</tr>
       	
       	<?php if($sub == 1 && $level1_item->type == 1): ?>
       		<?php foreach ($level1_item->sub_level2->level2 as $sub_level2): ?>
       		<tr style="display: none;" class="subtop_<?php echo $level1_item->type ?>_<?php echo $raw; ?>">
	       		<td>&nbsp;</td>
	       		<td>
	       			&nbsp;
	       		</td>
	       		<td style="text-align: center;">
	       			<?php echo date('d/m/Y',strtotime($sub_level2->created_date));?>
	       		</td>
	       		<td>
	       			<?php echo JText::_(WrdHelper::stringURLSafeAliasLang('WRD_MYACCOUNT_'.$sub_level2->des)); ?>
	       			
	       		</td>
	       		<td style="text-align: right;">
	       			<?php echo number_format($sub_level2->point,0,'.',','); ?>
	       		</td>
	       		<td style="text-align: right;">
	       			<?php if($sub_level2->expire != '0000-00-00'): ?>
       				<?php if(strtotime($sub_level2->expire) < time() && $sub_level2->expire != '0000-00-00'):?>
       					<font color="#800000"><?php echo date('d/m/Y',strtotime($sub_level2->expire));?></font>
       				<?php else: ?>
       					<?php echo date('d/m/Y',strtotime($sub_level2->expire));?>
       				<?php endif; ?>
       			<?php endif; ?>
	       		</td>
	       	</tr>
       		<?php endforeach; ?>
       	<?php endif; ?>
       	
       	
       	<?php if($sub == 1 && $level1_item->type == 0): ?>
       	<tr style="display: none;" class="subtop_<?php echo $level1_item->type ?>_<?php echo $raw; ?>">
       		<td colspan="6" style="padding: 2px 2px;">
	       		<table  class="twelve" cellpadding="0" cellspacing="0" style="margin: 0 0 1px;"> 
	       			<thead>
	       				<tr>
	       					<th><?php echo JTEXT::_('WRD_MYACCOUNT_INVOICE')?></th>
	            			<th><?php echo JTEXT::_('WRD_MYACCOUNT_DATE')?></th>
	            			<th><?php echo JTEXT::_('WRD_MYACCOUNT_OUTLET')?></th>
	            			<th><?php echo JTEXT::_('WRD_MYACCOUNT_PAX')?></th>
	            			<th><?php echo JTEXT::_('WRD_MYACCOUNT_TRANSACTION_TOTAL')?></th>
	            			<th><?php echo JTEXT::_('WRD_MYACCOUNT_POINT')?></th>
	       				</tr>
	       			</thead>
	       			<tbody>
	       				<?php foreach ($level1_item->sub_level2->level2 as $sub_level2): ?>
	       					<tr>
	       						<td width="15%" style="text-align: center;">
	       							<?php echo $sub_level2->transaction_id; ?>
	       						</td>
	       						<td width="15%" style="text-align: center;">
	       							<?php echo date('d/m/Y',strtotime($sub_level2->date_receipt));?>
	       						</td>
	       						<td width="25%">
	       							<?php echo $sub_level2->outlet_name; ?>
	       						</td>
	       						<td style="text-align: center;" width="10%">
	       							<?php echo $sub_level2->pax; ?>
	       						</td>
	       						<td style="text-align: right;" >
	       							
	       							<?php echo number_format($sub_level2->total,0,'.',','); ?>
	       						</td>
	       						<td style="text-align: right;">
	       							<?php echo number_format($sub_level2->point,0,',',',') ; ?>
	       						</td>
	       					</tr>
	       				<?php endforeach;?>
	       			</tbody>
	       		</table>
       		</td>
       	</tr>
       	<?php endif; ?>
       	
		<?php if($sub == 1 && $level1_item->type == 9): ?>
       	<tr style="display: none;" class="subtop_<?php echo $level1_item->type ?>_<?php echo $raw; ?>">
       		<td colspan="6" style="padding: 2px 2px;">
	       		<table class="tblmypoint" class="twelve" cellpadding="0" cellspacing="0" style="margin: 0 0 1px;"> 
	       			<thead>
	       				<tr>
	       					<th><?php echo JTEXT::_('WRD_MYACCOUNT_CODE')?></th>
	            			<th><?php echo JTEXT::_('WRD_MYACCOUNT_DATE')?></th>
	            			<th><?php echo JTEXT::_('WRD_MYACCOUNT_NAME')?></th>
	            			<th><?php echo JTEXT::_('WRD_MYACCOUNT_QUALITY')?></th>
	            			<th><?php echo JTEXT::_('WRD_MYACCOUNT_CASH')?></th>
	            			<th class="last_cell" ><?php echo JTEXT::_('WRD_MYACCOUNT_POINT')?></th>
	       				</tr>
	       			</thead>
	       			<tbody>
	       				<?php foreach ($level1_item->sub_level2->level2 as $sub_level2): ?>
	       					<tr>
	       						<td width="25%" style="text-align: center;">
	       							<?php echo $sub_level2->code; ?>
	       						</td>
	       						<td style="text-align: center;">
	       							<?php echo date('d/m/Y',strtotime($sub_level2->exchange_date));?>
	       						</td>
	       						<td width="35%">
	       							<?php 
	       							$product_name = unserialize($sub_level2->product_name);
	       							echo $product_name[$lang->getTag()]; 
	       							
	       							?>
	       						</td>
	       						<td width="5%" style="text-align: center;">
	       							<?php echo $sub_level2->quantity; ?>
	       						</td>
	       						<td width="25%" style="text-align: right;">
	       							<?php 
	       								echo number_format($sub_level2->cash,0,',',','); 
	       							?>
	       						</td>
	       						<td width="20%" style="text-align: right;">
	       							-<?php echo number_format($sub_level2->point,0,'.',',') ; ?>
	       							
	       						</td>
	       					</tr>
	       				<?php endforeach;?>
	       			</tbody>
	       		</table>
       		</td>
       	</tr>
       	<?php endif; ?>
       	
       <?php endforeach; ?>
    </tbody>
</table>

<?php 
   else:
?>
Empty
<?php endif; ?>
<script>
	jQuery(function () {
		jQuery('#dpFromYears').fdatepicker().on('changeDate', function(ev){
			jQuery("#special_range").val("0");
		});

		jQuery('#dpToYears').fdatepicker().on('changeDate', function(ev){
			jQuery("#special_range").val("0");
		});;
	});
</script>